# 🦜 : Let's try build from scratch <2024-09-09 一>
mkdir .pre
cd .pre
cp /media/me/F881-F23F/Downloads/archive.tar.gz  .

# 0. unzip the dependency sources
tar -xvzf archive.tar.gz
mv -v archive/* .
rmdir archive

# --------------------------------------------------
# 1. build boost
x=boost_1_86_0
x1=$x.tar.bz2
tar -xvjf $x1
echo "🐸 Boost extracted"
cd $x
./bootstrap.sh

./b2 --with-json --with-program_options --with-test --with-headers --with-log link=static
echo "🐸 Boost installed"

# --------------------------------------------------
# 2. build protobuf
x=protobuf
# cmake \
#     -DABSL_PROPAGATE_CXX_STD=ON \
#     -Dprotobuf_BUILD_TESTS=OFF \
#     -S $x -B build-$x
# 🦜 : Okay... there seems to be something wrong with the self-patched abseil.. so let's use the source.....
# b=/home/me/repo/google-cpp/abseil-cpp
b=/home/me/repo/google-cpp/abseil-cpp
cmake \
    "-DABSL_ROOT_DIR=$b" \
    -DABSL_PROPAGATE_CXX_STD=ON \
    -Dprotobuf_BUILD_TESTS=OFF \
    -S $x -B build-$x

cmake --build build-$x
cmake --install build-$x --prefix installed-$x

# --------------------------------------------------
# 3. build rocksdb
tar zxf v9.5.2.tar.gz
x=rocksdb-9.5.2
x1=`pwd`/build-rocksdb
make -C $x \
     OBJ_DIR=$x1 \
     static_lib

# 3.1 both static and shared
make -C $x \
     OBJ_DIR=$x1

x2=`pwd`/installed-rocksdb
make -C $x \
     OBJ_DIR=$x1 \
     PREFIX=$x2 \
     GTEST_DIR=`pwd`/$x/third-party/gtest-1.8.1/fused-src \
     install

# 🦜 : It seems like we have to help it with the GTEST_DIR, otherwise cmake will
# complain that relative path is not supported in INTERFACE_INCLUDE_DIR

# 3.1. introduce it to pkgconfig
ls installed-rocksdb/lib/pkgconfig/rocksdb.pc
sudo ln -s `pwd`/installed-rocksdb/lib/pkgconfig/rocksdb.pc /usr/share/pkgconfig/rocksdb.pc
# 3.2 check if it's working
pkg-config --cflags --libs rocksdb

# install libz/openssl
sudo apt install zlib1g-dev libssl-dev
sudo -E apt install zlib1g-dev libssl-dev
# /sbin/ldconfig -p| grep libz.so


# --------------------------------------------------
# 4. try build (release)
conda deactivate
cd ..
rm -v weak/include/.generated_pb/*
rm -rv build-weak
cmake -S weak  -B build-weak
cmake --build build-weak
